﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Drawing;

namespace libLite
{
    // napraviti i klasu KNJIGA i iz nje zaslejdjivati
    public class dynKnjiga : FlowLayoutPanel
    {
        private string naslov;
        private string podnaslov;
        private string id;
        private string isbn;
        private string slobodnih;
        private Button btnImage;
        private Label lblTitle;
        private ContextMenuStrip bookStrip;
        //   private string slobodanID;

        public dynKnjiga(string n, string p, string i, string isb, Image img)
        {
            naslov = n;
            podnaslov = p;
            id = i;
            isbn = isb;

            initButt(id, img);
            initLbl(id, naslov);
            initBookStrip(id);
            initialize(id);
        }

        private void initBookStrip(string aid)
        {
            bookStrip = new ContextMenuStrip();

            // definicija itema
            ToolStripButton editBook = new ToolStripButton();
            editBook.Name = "eb"+aid;
            editBook.Size = new System.Drawing.Size(152, 22);
            editBook.Text = "Edituj";
            editBook.Click += new System.EventHandler(editBook_Click);

            ToolStripButton deleteBook = new ToolStripButton();
            deleteBook.Name = "db" + aid;
            deleteBook.Size = new System.Drawing.Size(152, 22);
            deleteBook.Text = "Izbrisi";
            deleteBook.Click += new System.EventHandler(deleteBook_Click);

            bookStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            editBook,
            deleteBook});
            bookStrip.Name = "cs"+aid;
            bookStrip.Size = new System.Drawing.Size(114, 48);
        }

        private void initialize(string aid)
        {
            this.Controls.Add(btnImage);
            this.Controls.Add(lblTitle);
            this.FlowDirection = System.Windows.Forms.FlowDirection.TopDown;
            this.Name = aid;
            this.Size = new System.Drawing.Size(131, 179);
            this.Click += new EventHandler(book_Click);
            this.ContextMenuStrip = bookStrip;
        }

        private void initLbl(string aid, string title)
        {
            lblTitle = new Label();
            lblTitle.AutoEllipsis = true;
            lblTitle.AutoSize = true;
            lblTitle.Dock = System.Windows.Forms.DockStyle.Fill;
            lblTitle.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
            this.SetFlowBreak(lblTitle, true);
            lblTitle.Location = new System.Drawing.Point(3, 156);
            lblTitle.Name = aid;
            lblTitle.Size = new System.Drawing.Size(128, 13);
            lblTitle.Text = title;
            lblTitle.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
        }

        private void initButt(string aid, Image img)
        {
            btnImage = new Button();
            btnImage.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
            btnImage.FlatAppearance.BorderSize = 0;
            btnImage.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
            btnImage.Location = new System.Drawing.Point(3, 3);
            btnImage.Name = aid;
            btnImage.Image = img;
            btnImage.Size = new System.Drawing.Size(128, 150);
            btnImage.UseVisualStyleBackColor = true;
        }

        public string gNaslov() { return naslov; }
        public string gPodnaslov() { return podnaslov; }
        public string gID() { return id; }
        public string gISBN() { return isbn; }
        public string gSlobodnih() { return slobodnih; }
        // public string gSlobodanID() { return slobodanID; }

        /// <summary>
        /// List copies of the book object
        /// </summary>
        ///  <param name="onlyAviable">List only available copies</param>
        ///  <returns>ArrayList of id's</returns>
        public ArrayList listAvailableCopies(bool onlyAvailable)
        {
            ArrayList priv = new ArrayList();
            String qString = "select id from kopija_knjige where fk_katalog=" + id;
            if (onlyAvailable) qString += " AND id not in (select fk_kopija from transakcije where vracena is NULL) group by id";
         //   OdbcCommand upit = new OdbcCommand(qString, KonWin.konekcija.ConObj);
        //    OdbcDataReader citac = upit.ExecuteReader();
        //    while (citac.Read())
        //        priv.Add(citac[0].ToString());
            return priv;
        }

        public void sNaslov(string i) { naslov = i; }
        public void sPodnaslov(string i) { podnaslov = i; }
        public void sID(string i) { id = i; }
        public void sISBN(string i) { isbn = i; }

        /// <summary>
        /// List exemplars of the book object
        /// </summary>
        ///  <param name="onlyAviable">List only available exemplars</param>
        ///  <returns>ArrayList of id's</returns>
        public void checkCopyCount()
        {
            string SQLstr = "select id from kopija_knjige where fk_katalog=" + id + " AND id not in (select fk_kopija from transakcije where vracena is NULL) group by id";
         //   OdbcCommand upit = new OdbcCommand(SQLstr, KonWin.konekcija.ConObj);
         //   OdbcDataReader citac = upit.ExecuteReader();
         //   citac.Read();
            //   slobodanID = citac[0].ToString();
        //    slobodnih = citac.RecordsAffected.ToString();
        }


        private void editBook_Click(object sender, EventArgs e)
        {

        }


        private void deleteBook_Click(object sender, EventArgs e)
        {

        }


        private void book_Click(object sender, EventArgs e)
        {

        }
    }

    public class dynCheck : CheckBox
    {
        private string naslov;
        private string datum;
        private string id;

        public dynCheck(string n, string d, string i)
        {
            naslov = n;
            datum = d;
            id = i;
        }

        public string gNaslov() { return naslov; }
        public string gDatum() { return datum; }
        public string gID() { return id; }

        public void sNaslov(string i) { naslov = i; }
        public void sDatum(string i) { datum = i; }
        public void sID(string i) { id = i; }
    }


    public class dynKorisnik : Button
    {
        private string ime;
        private string prezime;
        private string zPristup;
        private string funkcija;
        private string id;
        private string username;

        public dynKorisnik(string n, string p, string i, string u)
        {
            ime = n;
            prezime = p;
            id = i;
            username = u;
        }

        public void sIme(string i) { ime = i; }
        public void sPrezime(string i) { prezime = i; }
        public void sPristup(string i) { zPristup = i; }
        public void sFunkcija(string i) { funkcija = i; }
        public void sID(string i) { id = i; }
        public string gIme() { return ime; }
        public string gID() { return id; }
        public string gPrezime() { return prezime; }
        public string gPristup() { return zPristup; }
        public string gFunkcija() { return funkcija; }
    }



    public class Korisnik
    {
        private string ime;
        private string prezime;
        private string zPristup;
        private string funkcija;
        private string user;
        private string id;

        public Korisnik()
        {
            id = "";
        }
        public void sIme(string i) { ime = i; }
        public void sPrezime(string i) { prezime = i; }
        public void sPristup(string i) { zPristup = i; }
        public void sFunkcija(string i) { funkcija = i; }
        public void sID(string i) { id = i; }
        public void sUser(string i) { user = i; }
        public string gIme() { return ime; }
        public string gID() { return id; }
        public string gUser() { return user; }
        public string gPrezime() { return prezime; }
        public string gPristup() { return zPristup; }
        public string gFunkcija() { return funkcija; }
    }
}
